package com.biwin.module.jwt.api.properties;

import com.biwin.module.jwt.api.enums.TokenManagerPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.concurrent.TimeUnit;

/**
 * BiWin Framework Jwt Token Properties
 *
 * @author biwin
 * @since 0.0.1
 */
@ConfigurationProperties("biwin.jwt")
public class BiWinJwtProperties {

    /**
     * Token 失效时间
     */
    private long ttl = 1800000L;

    /**
     * Token 失效时间的单位
     */
    private TimeUnit timeUnit = TimeUnit.MILLISECONDS;

    /**
     * Jwt Token 加密key
     */
    private String key = "biwin";

    /**
     * Token 创建策略
     */
    private TokenManagerPolicy.Create createTokenPolicy = TokenManagerPolicy.Create.ONLY_FIRST;

    /**
     * Token 失效策略
     */
    private TokenManagerPolicy.Invalid invalidTokenPolicy;

    /**
     * 同一个用户最多同时在线人数
     * BiWin框架默认最大仅支持10个用户, 不配置或配置为0或配置大于10的逻辑都只能同时在线10个相同用户
     */
    private int maxNum = 1;

    /**
     * 存入 redis 中的 key 的前缀
     */
    private String prefix = "BIWIN";

    private String project = "BIWIN";

    public long getTtl() {
        return ttl;
    }

    public void setTtl(long ttl) {
        this.ttl = ttl;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }

    public void setTimeUnit(TimeUnit timeUnit) {
        this.timeUnit = timeUnit;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public TokenManagerPolicy.Create getCreateTokenPolicy() {
        return createTokenPolicy;
    }

    public void setCreateTokenPolicy(TokenManagerPolicy.Create createTokenPolicy) {
        this.createTokenPolicy = createTokenPolicy;
    }

    public TokenManagerPolicy.Invalid getInvalidTokenPolicy() {
        return invalidTokenPolicy;
    }

    public void setInvalidTokenPolicy(TokenManagerPolicy.Invalid invalidTokenPolicy) {
        this.invalidTokenPolicy = invalidTokenPolicy;
    }

    public int getMaxNum() {
        return maxNum;
    }

    public void setMaxNum(int maxNum) {
        if (0 > maxNum || 10 < maxNum) {
            this.maxNum = 10;
        } else {
            this.maxNum = maxNum;
        }
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }
}
